package xml_tests.xmlJTreeView;

import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;

import xml_tests.BOOK.Book;

public class ObjectModelToTreeModel {

	public static DefaultMutableTreeNode getTreeOfModel(List<Book> bookL) {
		DefaultMutableTreeNode root = new DefaultMutableTreeNode("Catalog");
		for (Book bk : bookL) {
			DefaultMutableTreeNode book = new DefaultMutableTreeNode("Book " + bk.getTitle() + "BookId: " + bk.getId());

			book.add(new DefaultMutableTreeNode("Language: " + bk.getLang()));
			book.add(new DefaultMutableTreeNode("Isbn :" + bk.getIsbn()));
			book.add(new DefaultMutableTreeNode("Registration Date:" + bk.getRegDate().toString()));
			book.add(new DefaultMutableTreeNode("Publisher :" + bk.getPublisher()));

			DefaultMutableTreeNode authors = new DefaultMutableTreeNode("Authors:");
			for (String auths : bk.getAuthors()) {
				authors.add(new DefaultMutableTreeNode(auths));
			}
			book.add(authors);
			root.add(book);
		}

		return root;
	}
}
